<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/5 0005
 * Time: 15:41
 */
class mysqlpub{
    private function mylink(){
        $host = '60.205.213.189';
        $name = 'root';
        $pass = 'caowen83760250';
        $database = 'php200';
        $link = mysqli_connect($host,$name,$pass,$database);
        if($link){
            return $link;
        }else{
            return mysqli_connect_error();
        }
    }
//查询封装
    /**
     * @param $sql
     * @return array
     */
//多个数据查询
    function query($sql){
        $links = $this ->mylink();
        $res = mysqli_query($links,$sql);
        $arr = [];
        while($data = mysqli_fetch_assoc($res)){
            $arr[] = $data;
        }
        return $arr;
    }
//只查询一个数据
    function find($sql){
        $links = $this ->mylink();
        $res = mysqli_query($links,$sql);
        $data = mysqli_fetch_assoc($res);
        return $data;
    }
    /**
     * @param $sql
     * @return bool|mysqli_result
     */
//新增封装  修改  删除
    function insert($sql){
        $links = $this ->mylink();
        $res = mysqli_query($links,$sql);
        return $res;
    }
}